
const { createProxyMiddleware } = require('http-proxy-middleware');
// const target="https://ouyujingcheng.com"
const target="http://127.0.0.1:8080"
module.exports = function (app) {
    app.use(
        '/user',
        createProxyMiddleware({
            target, // 需要跨域处理的请求地址
            changeOrigin: true,
            pathRewrite: { // 请求中去除/api
                "^/user": "/user"
            },
            secure:false,
            onProxyReq: function onProxyReq(proxyReq, req, res) {
                // 我就打个log康康
                console.log('-->  ', req.method, req.baseUrl, '->', proxyReq.host + proxyReq.path);
            }
        })
    ),
        app.use(
            '/api',
            createProxyMiddleware({
                target, // 需要跨域处理的请求地址
                changeOrigin: true,
                pathRewrite: { // 请求中去除/api
                    "^/api": "/api"
                },
                secure:false,
                onProxyReq: function onProxyReq(proxyReq, req, res) {
                    // 我就打个log康康
                    console.log('-->  ', req.method, req.baseUrl, '->', proxyReq.host + proxyReq.path);
                }
            })
        ),
        app.use(
            '/gzh',
            createProxyMiddleware({
                target, // 需要跨域处理的请求地址
                changeOrigin: true,
                pathRewrite: { // 请求中去除/api
                    "^/api": "/api"
                },
                secure:false,
                onProxyReq: function onProxyReq(proxyReq, req, res) {
                    // 我就打个log康康
                    console.log('-->  ', req.method, req.baseUrl, '->', proxyReq.host + proxyReq.path);
                }
            })
        ),
        app.use(
            '/app',
            createProxyMiddleware({
                target, // 需要跨域处理的请求地址
                changeOrigin: true,
                pathRewrite: { // 请求中去除/api
                    "^/app": "/app"
                },
                secure:false,
                onProxyReq: function onProxyReq(proxyReq, req, res) {
                    // 我就打个log康康
                    console.log('-->  ', req.method, req.baseUrl, '->', proxyReq.host + proxyReq.path);
                }
            })
        ),
        app.use(
            '/uploads',
            createProxyMiddleware({
                target, // 需要跨域处理的请求地址
                changeOrigin: true,
                pathRewrite: { // 请求中去除/api
                    "^/uploads": "/uploads"
                },
                secure:false,
                onProxyReq: function onProxyReq(proxyReq, req, res) {
                    // 我就打个log康康
                    console.log('-->  ', req.method, req.baseUrl, '->', proxyReq.host + proxyReq.path);
                }
            })
        )
};
